package Sort;

//选择排序
public class SelectionSort {
    public static void sort(int[] a){
        //1.选择轮数a.length-1
        //2.交换索引位置(right) 初始a.length - 1,每次递减
        for (int right = a.length - 1; right > 0 ; right--) {
            int max = right;
            for (int i = 0; i < right; i++) {
                if(a[i] > a[max]){
                    max = i;
                }
            }
            swap(a,max, right);
        }
    }
    private static void swap(int[] a,int i,int j){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
